﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Post : System.Web.UI.Page
{
	private string cs = System.Configuration.ConfigurationManager.ConnectionStrings["Resist"].ConnectionString;
	
	protected void Page_Load(object sender, EventArgs e)
    {
		string FriendlyName  = "";
		try { FriendlyName = Request.Url.AbsoluteUri.Substring(Request.Url.AbsoluteUri.LastIndexOf('?') + 1); }
		catch { Response.Redirect("."); }

		DataRow[] posts = KC.DataAccess.Global.Global.CallSql_Query(cs, "select * from posts where Friendlyname='" + FriendlyName.Replace("'", "''") + "'").Select();
		if (posts.Length == 0) { Response.Redirect("."); return; }
		DataRow dr = posts[0];

		Header.Controls.Add(new LiteralControl("<link rel=\"canonical\" href=\"http://www.ResistOccupation.com/Post.aspx?" + FriendlyName + "\" />"));
		Header.Controls.Add(new LiteralControl() { Text = "<meta property=\"og:title\" content=\"" + dr["Title"].ToString() + "\" />\r\n" });
		Title = dr["Title"].ToString();
		lblBody.Text = dr["Body"].ToString().Replace("!break", "");
		lblCreated.Text = ((DateTime)dr["Created"]).ToString("MM/dd/yyyy hh:mm ttt") + " MT";
		hlTitle.Text = dr["Title"].ToString();
		hlTitle.NavigateUrl = "http://www.ResistOccupation.com/Post.aspx?" + dr["Friendlyname"].ToString();
		hlTitle.ToolTip = dr["Description"].ToString();
		if (dr["Image"].GetType() != typeof(DBNull)) {
			img.Visible = true;
			img.ImageUrl = "Image.aspx?" + dr["ID"].ToString(); }
		lblComments.Text = site.GetFacebookCommentsScript("http://www.ResistOccupation.com/Post.aspx?" + FriendlyName);
		lblFacebook.Text = site.GetFacebookLikeButton("http://www.ResistOccupation.com/Post.aspx?" + FriendlyName);
    }
}